package com.jnu.weather.controller;


import com.jnu.weather.domain.WeatherResponse;
import com.jnu.weather.po.City;
import com.jnu.weather.service.CityService;
import com.jnu.weather.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import org.thymeleaf.spring5.view.ThymeleafViewResolver;

import java.util.List;

@Controller
public class WeatherController {
    ThymeleafProperties thymeleafProperties;
    @Autowired
    WeatherService weatherService;
    @Autowired
    CityService cityService;
    @RequestMapping("/getWeather")
    public ModelAndView getWeather(Model model, String cityid){
        City city =cityService.findAllByCityid(cityid);
        System.out.println("cityid:"+cityid);
        System.out.println("city:"+city.getCity());
        List<City> cityList=cityService.findAllCity();
        model.addAttribute("cityList",cityList);
       return new ModelAndView("weather","weatherdata",weatherService.weatherApi(cityid,city.getCity()));
    }
}
